package biz.inspeed.test.mina;
import java.net.InetSocketAddress;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.future.CloseFuture;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


 
public class MinaClient {
	private static final Logger log = LoggerFactory.getLogger(MinaClient.class);
    public static void main(String[] args) {
    	System.out.println("00000000000000");
        NioSocketConnector connector = new NioSocketConnector();

        DefaultIoFilterChainBuilder chain = connector.getFilterChain();
        ProtocolCodecFilter filter = new ProtocolCodecFilter(
                new ObjectSerializationCodecFactory());
        chain.addLast("objectFilter",filter);
 
        connector.setHandler(new MinaClientHanlder());
        // Set connect timeout.
        connector.setConnectTimeoutCheckInterval(1);
        System.out.println("============11111111111111");
        ConnectFuture cf = connector.connect(new InetSocketAddress("192.168.0.224", 1000));
        cf.awaitUninterruptibly();
        
        cf.addListener(new ConnectorListener1());
        
        System.out.println("22222222222222");
        // Wait for the connection attempt to be finished.
        cf.awaitUninterruptibly();
        System.out.println("333333333333333");
        CloseFuture closeFuture = cf.getSession().getCloseFuture();
        closeFuture.addListener(new Listener1());
        System.out.println("closeFuture" + closeFuture.getClass().getCanonicalName());
        closeFuture.awaitUninterruptibly();
        System.out.println("4444444444444");
        connector.dispose();
        System.out.println("5555555555555555555");
 
    }
}
